package de.ama.view;

import de.ama.crawler.Entry;
import de.ama.util.Util;

import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.util.Vector;

/**
 * Created by IntelliJ IDEA.
 * User: ama
 * Date: 15.02.11
 * Time: 19:34
 * To change this template use File | Settings | File Templates.
 */
public class EntryCellREnderer extends JList implements TableCellRenderer {
    public EntryCellREnderer() {
        setCellRenderer(new MyListCellRenderer());
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Vector v = new Vector();

        setBackground(isSelected ? Color.GRAY : Color.DARK_GRAY);

        if (value instanceof Entry) {
            final Entry e = (Entry) value;
            e.setSelected(isSelected);
            ImageIcon image = Util.loadIcon(e.getImagePath());
            JLabel thumb = new JLabel(image);
            v.add(thumb);
            JLabel title = new JLabel(e.getTitle(), JLabel.CENTER);
            title.setForeground(Color.LIGHT_GRAY);
            v.add(title);
            setToolTipText(e.getPath()+ " "+e.getTags());
        }

        setListData(v);
        return this;
    }

    class MyListCellRenderer implements ListCellRenderer {
        MyListCellRenderer() {

            setBackground(Color.DARK_GRAY);
        }

        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            return (JComponent) value;
        }
    }

}
